/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.lnu.ums.service.impl;

import edu.lnu.ums.dal.ICountryDAO;
import edu.lnu.ums.dal.IFacultyDAO;
import edu.lnu.ums.dal.IHumanDAO;
import edu.lnu.ums.dal.IMonthsDAO;
import edu.lnu.ums.dal.ISexDAO;
import edu.lnu.ums.dal.IStudentDAO;
import edu.lnu.ums.dal.ISubjectDAO;
import edu.lnu.ums.dal.ITeacherDAO;
import edu.lnu.ums.dal.IUMSTypeDAO;
import edu.lnu.ums.dal.IWorkerDAO;
import edu.lnu.ums.dal.factories.FactoriesCache;
import edu.lnu.ums.entities.Faculty;
import edu.lnu.ums.entities.Human;
import edu.lnu.ums.entities.Student;
import edu.lnu.ums.entities.Teacher;
import edu.lnu.ums.entities.Worker;
import edu.lnu.ums.entities.core.UMSObject;
import edu.lnu.ums.entities.dictionaries.Country;
import edu.lnu.ums.entities.dictionaries.Months;
import edu.lnu.ums.entities.dictionaries.Sex;
import edu.lnu.ums.entities.dictionaries.Subject;
import edu.lnu.ums.entities.dictionaries.UMSType;
import edu.lnu.ums.service.IDictionaryService;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

@Stateless
public class DictionaryService implements IDictionaryService {

    @EJB(mappedName = "UMS/SexDAO/local")
    private ISexDAO sexDao;

     @EJB(mappedName = "UMS/MonthsDAO/local")
     private IMonthsDAO monthsDao;
    
    @EJB(mappedName = "UMS/CountryDAO/local")
    private ICountryDAO countryDao;
    @EJB(mappedName = "UMS/UMSTypeDAO/local")
    private IUMSTypeDAO typeDAO;
    @EJB(mappedName = "UMS/SubjectDAO/local")
    private ISubjectDAO subjectDao;
    @EJB(mappedName = "UMS/WorkerDAO/local")
    private IWorkerDAO workerDao;
    @EJB(mappedName = "UMS/StudentDAO/local")
    private IStudentDAO studentDao;
    @EJB(mappedName = "UMS/TeacherDAO/local")
    private ITeacherDAO teacherDao;
    @EJB(mappedName = "UMS/FacultyDAO/local")
    private IFacultyDAO facultyDAO;
    @EJB(mappedName = "UMS/HumanDAO/local")
    private IHumanDAO humanDAO;

    @Override
    public List<UMSType> getTypes(UMSObject selectedObject) {
        return typeDAO.getAllOrdered(FactoriesCache.getInstance().
                getFactory(FactoriesCache.DEFAULT_FACTORY_NAME));
    }

    @Override
    public UMSType getUMSTypeByName(UMSObject selectedObject, String name) {
        return typeDAO.getByName(FactoriesCache.getInstance().getFactory(
                FactoriesCache.DEFAULT_FACTORY_NAME), name);

    }

    @Override
    public List<Sex> getSexes(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return sexDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public Sex getSexByName(UMSObject selectedObject, String name) {
        if (selectedObject == null) {
            return null;
        } else {
            return sexDao.getByName(selectedObject.getFactory(), name);
        }
    }

    @Override
    public List<Months> getMonths(UMSObject selectedObject) {
        return monthsDao.getAllOrdered(selectedObject.getFactory());
    }

    @Override
    public Months getMonthsByName(UMSObject selectedObject, String name) {
        return monthsDao.getByName(selectedObject.getFactory(), name);
    }

    @Override
    public List<Country> getCountries(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return countryDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Subject> getSubjects(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return subjectDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Worker> getWorkers(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return workerDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Student> getStudents(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return studentDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Teacher> getTeachers(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return teacherDao.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Faculty> getFaculties(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return facultyDAO.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public List<Human> getHumans(UMSObject selectedObject) {
        if (selectedObject == null) {
            return Collections.EMPTY_LIST;
        } else {
            return humanDAO.getAllOrdered(selectedObject.getFactory());
        }
    }

    @Override
    public Country getCountryByName(UMSObject selectedObject, String name) {
        if (selectedObject == null) {
             return null;
        } else {
            return countryDao.getByName(selectedObject.getFactory(), name);
        }
    }

    @Override
    public Subject getSubjectByName(UMSObject selectedObject, String name) {
        if (selectedObject == null) {
            return null;
        } else {
            return subjectDao.getByName(selectedObject.getFactory(), name);
        }
    }

    @Override
    public Human getHumanById(UMSObject selectedObject, Long id) {
        if (selectedObject == null) {
            return null;
        } else {
            return humanDAO.getById(selectedObject.getFactory(), id);
        }
    }

    @Override
    public Faculty getFacultyByFullName(UMSObject selectedObject, String name) {
        if (selectedObject == null) {
            return null;
        } else {
            return facultyDAO.getByName(selectedObject.getFactory(), name);
        }
    }
}
